﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dal;
using Dtl;

namespace Bll
{
    public class UserBlo
    {
        public static int SetUser(string idUser,string userName, string name, string pass, string mail, string skype, string msn, string phone, string phone2, int rol, string status,bool encriptar)
        {
            User cUser = new User();
            try
            {
                cUser.Id = int.Parse(idUser);
            }
            catch {
                cUser.Id = 0;
            }
            cUser.UserName = userName;
            cUser.Name = name;
            if (encriptar)
            {
                cUser.Password = Bll.SecurityBlo.EncryptString(pass);
            }
            else {
                cUser.Password = pass;
            }
            cUser.Email = mail;
            cUser.Skype = skype;
            cUser.MSN = msn;
            cUser.Phone1 = phone;
            cUser.Phone2 = phone2;
            cUser.Role = rol;
            cUser.Status = status;
            return UserDao.SetUser(cUser);
        }

        public static int SetUserPassword(string UserName, string Password)
        {
            return UserDao.SetUserPassword(UserName, Bll.SecurityBlo.EncryptString(Password));
        }

        public static int ValidateUser(string UserName, string Password)
        {
            return UserDao.ValidateUser(UserName, Bll.SecurityBlo.EncryptString(Password));
        }

        public static string getRols()
        {
            System.Data.DataSet ds = UserDao.getRols();
            return ds == null ? null : ds.GetXml();
        }

        public static System.Data.DataSet getUserbyUsername(string Username)
        {
            return UserDao.getUserbyUserName(Username);
        }

        public static System.Data.DataSet getUsers() {
            return UserDao.getUsers();
        }
    }
}
